import {defineConfig} from 'vite'
import vue from '@vitejs/plugin-vue'
import path from "path"
// icon
import {createSvgIconsPlugin} from 'vite-plugin-svg-icons'

// https://vitejs.dev/config/
export default defineConfig({
  server: {
    host:"0.0.0.0",
    //用来配置跨域
    proxy: {
      '/api': {
        // 要代理的服务器地址  这里不用写 api
        // target: 'https://api.imooc-admin.lgdsunday.club/',
        // 用apifox模拟接口返回
        // target: 'http://127.0.0.1:4523/m1/2281705-0-default/',

        target: 'https://mock.apifox.cn/m1/2281705-0-default/',
        changeOrigin: true // 是否跨域
      },
    }
  },
  plugins: [
    vue(),
    createSvgIconsPlugin({
      // 指定需要缓存的图标文件夹
      iconDirs: [path.resolve(process.cwd(), 'src/components/SvgIcon/svg')],
      // 指定symbolld格式
      symbolId: 'icon-[dir]-[name]'
    }),
  ],
  css: {
    preprocessorOptions: {
      scss: {
        additionalData:`
            @use "./src/styles/global.scss" as *;
          `
      }
    }
  },
  root: './',
  base: './',
  resolve: {
    // 导入时想要省略的扩展名列表
    extensions: ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json', '.vue'],
    alias: {
      '@': path.resolve(__dirname, './src')
    }
  }
})
